package regular;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.hadoop.io.Writable;

public class GraphQuery {
	ArrayList<VertexQ> Vq;
	VertexQ us;
	VertexQ ut;

	public GraphQuery(ArrayList<VertexQ> Vq, VertexQ us, VertexQ ut) {
		this.Vq = Vq;
		this.us = us;
		this.ut = ut;
	}
	
	
	@Override
	public String toString(){
		String out="";
		for(VertexQ v: Vq){
			out += v.toString()+"\n";
		}
		return out;
	}
}

class VertexQ implements Writable {
	String stateName;
	ArrayList<EdgeQ> childrenState;

	public VertexQ() {
	}

	public VertexQ(String stateName) {
		this.stateName = stateName;
		this.childrenState = new ArrayList<EdgeQ>();
	}

	public VertexQ(String nameState, ArrayList<EdgeQ> childrenState) {
		this.stateName = nameState;
		this.childrenState = childrenState;
	}

	public String Lq() {
		return this.stateName;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		stateName = in.readUTF();
		int size = in.readInt();
		for(int i=0;i<size;i++){
			EdgeQ edge = new EdgeQ();
			edge.readFields(in);
			childrenState.add(edge);
		}		
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeUTF(stateName);
		int n = childrenState.size();
		out.writeInt(n);
		for (EdgeQ edge : childrenState)
			edge.write(out);

	}
	
	@Override
	public String toString(){
		String out=stateName+": ";
		for(EdgeQ e: childrenState){
			out += "\t"+e.target;
		}
		return out;
	}
}

class EdgeQ implements Writable {
	String target;

	public EdgeQ() {
		target = null;
	}

	public EdgeQ(String target) {
		this.target = target;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		target = in.readUTF();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeUTF(target);
	}
}